This forum is closed to new posts and
responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:
',--------------------------------------------------------------------------[ C R E A T E D I R S ]-----
'| What : CREATEDIRS LotusScript Property
'| Who : Dave "Rags" Gilmore, Highland Technology Services, Inc.
'| When : April 10, 2007
'| Why : Make sure all directories of a path exist, ala the Java File.createDirs() method.
''------------------------------------------------------------------------------------------------------
Private Function createDirs(path As String) As Boolean
On Error Goto CP_DOH
Dim drive As String
Dim orgDir As String
Dim part As String
Dim rest As String
Dim ndx As Long
Dim first As Boolean
'
part=""
drive=""
createDirs=True
first=True
orgDir=Curdir$
rest=path
ndx=Instr(rest, "\")
Me.pl.add |DFile is creating dirs for '|+path+|"|
While(ndx>0)
If(part="") Then part=Left$(rest, ndx-1) Else part=part+"\"+Left$(rest, ndx-1)
rest=Mid$(rest, ndx+1)
If(first And Instr(part, ":")>0) Then
Me.pl.add |- Set drive |+part
drive=Curdrive$
Chdrive part
first=False
Else
If(Dir$(part, ATTR_DIRECTORY)="") Then
Me.pl.add |- Mkdir |+part
Mkdir(part)
Else
Me.pl.add |- Reuse |+part
End If
End If
ndx=Instr(rest, "\")
Wend
If(Instr(rest, ".")<1 And rest<>"") Then
part=part+"\"+rest
If(Dir$(part)="") Then Mkdir(part)
End If
CP_DONE:
If(drive<>"") Then Chdrive drive
Chdir orgDir
Exit Function
CP_DOH:
createDirs=False
Me.pl.err Err, | line | & Erl & | of createDirs: "|+Error$+|"|
Resume CP_DONE
End Function
- As you can see, it caches the current drive and directory, and returns to them on exit, even if the error handler runs. This *must* be done because LotusScript uses a global directory, and if it's not restored the code will break other places, like trying to open a database that should default relative to the notes/data directory, but doesn't.
- Here's one of several places that uses createDirs:
path=Me.lit.CLIENT_BASE_PATH+"\"
If(Me.edID="") Then path=path+Me.note.noteID Else path=path+Me.edID
path=path+"\"+Me.embed.source
createDirs(path)
noFile=(Dir$(path)="")
If(noFile) Then Me.embed.extractFile(path)
' --- what is done with file omitted ----
If(noFile And Dir$(path)<>"") Then ' We extracted, we delete
Me.pl.add | Nuking: "|+path+|"|
Kill path ' file
path=Strleftback(path, "\") ' See in the "debugger"
Me.pl.add | Rmdir: "|+path+|"|
Rmdir path ' noteID/edID directory
End If
- This doesn't change the current directory at all, unless Dir$() does that, but I've never noticed it doing that, and help doesn't say it does that. And the log created by the above code:
DFile is creating dirs for 'C:\WebSvc\eDocs\Files\0901e24080714a5f\EXEC-2010-006716.pdf"
- Set drive C:
- Reuse C:\WebSvc
- Reuse C:\WebSvc\eDocs
- Reuse C:\WebSvc\eDocs\Files
- Mkdir C:\WebSvc\eDocs\Files\0901e24080714a5f
Nuking: "C:\WebSvc\eDocs\Files\0901e24080714a5f\EXEC-2010-006716.pdf"
Rmdir: "C:\WebSvc\eDocs\Files\0901e24080714a5f"
Error(75): line 413 of DFile.digest(C:\WebSvc\eDocs\Files\0901e24080714a5f): "Path/file access error"
- So it deletes the file but it won't remove the subdirectory *it* created. One may say, well the directory isn't empty, but it is - if I go to the server where this code runs nothing exists in the directory it fails to remove, and if I attempt to remove it manually I get an "in use" violation. If I use a tool to look at who has a handle to that directory, it's Domino that has ahold of it and won't let it go. This error always happens, and has always happened any time I extract a file and attempt to delete it's (temporary) sudbdirectory. Since it doesn't break anything I've always ignored it.
- In the past I've seen this over and over and over with files, when I create them using LotusScript. For instance, I may write data to a file and then close it. Even after the Agent is done, Domino refuses to let go of the file until it's bounced. It happened so consistently that I put code in to mangle file names, with a digit sequence for uniqueness, so the Agent wouldn't barf because it could not append to its *own* file. Domino had that file and gosh darn it no one could touch it, not even Domino.
- But, as mentioned, in the Grand Scheme of flakiness, this ranks next to zero. It's trivially simple to work around or plain ignore. In terms of operation I could care less. But declaring this doesn't happen does not actually make it so, and people searching this forum should be fully aware of how this operates.
Hope this helps...
Feedback response number DGIE85RJXX created by ~Holly Zekhipisonnivu on 05/24/2010